using System;
using System.Collections.Generic;
using System.Threading;

namespace Monorf.Net
{
    public class InitiationDispatcher
    {
        private BaseListener<CommunicationState> m_listener = null;
        private List<IEventHandler> m_handlers = null;
        private IEventHandler m_handler = null;
        //private Queue<UdpCommunicationState> m_messageBuffer = null;
        private static InitiationDispatcher s_instance = new InitiationDispatcher();


        public InitiationDispatcher()
        {
            m_handlers = new List<IEventHandler>(5);
        }


        /// <summary>
        /// event dispacthing singleton
        /// </summary>
        public static InitiationDispatcher Instance { get { return s_instance; } }


        /// <summary>
        /// register new even handler
        /// </summary>
        /// <param name="handler"></param>
        //public void RegisterHandle(IEventHandler handler, 
        //            Queue<UdpCommunicationState> m_messageBuffer)
        //{
        //    m_handlers.Add(eventType, handler);
        //}

        public void RegisterHandler(IEventHandler handler)
        {
            m_handler = handler;
        }

        /// <summary>
        /// unregister new even handler
        /// </summary>
        /// <param name="handler"></param>
        public void UnRegisterHandle(EventType eventType)
        {
            //m_handlers.Remove(eventType);
        }

        public void UnRegisterHandle(IEventHandler handler)
        {
            m_handler = null;
        }

        /// <summary>
        /// handle events loog
        /// </summary>
        /// <param name="timeout"></param>
        //public void HandleEvents(TimeSpan timeout, Queue<UdpCommunicationState> inputData)
        //{
        //    m_inputData = inputData;
        //    WaitCallback receiveData = new WaitCallback(ReceiveData);
        //    m_listener = new UdpListener(8192, receiveData);

        //    m_listener.Listen<Handle>(m_handler.Handle);
        //}

        private void ReceiveData(Object state)
        {
            //lock (m_inputData)
            //{
            //    m_inputData.Enqueue((UdpCommunicationState)state);
            //}
        }
    }
}
